package com.ygou.service.impl.solr;

import java.util.List;

import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.common.SolrInputDocument;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ygou.mapper.solr.GoodsSearchMapper;
import com.ygou.pojo.solr.GoodsSearch;
import com.ygou.service.solr.GoodsSearchService;

@Service
public class GoodsSearchServiceImpl implements GoodsSearchService {

	@Autowired
	private GoodsSearchMapper goodsSearchMapper;
	@Autowired
	private SolrServer server;
	
	
public int addfindGoodsAll() {
		
		try {
			List<GoodsSearch> list=goodsSearchMapper.addfindGoodsAll();
			//把商品信息写到索引库
			for (GoodsSearch g : list) {
				SolrInputDocument document=new SolrInputDocument();
				document.setField("id", g.getId());
				document.setField("item_title", g.getTitle());
				document.setField("item_price", g.getPrice());
				document.setField("item_hot", g.getHot());
				document.setField("item_new", g.getIsnew());
				document.setField("item_cnum", g.getCnum());
				document.setField("item_image", g.getImg());
				//document.setField("item_category_name", g.);
				/*document.setField("item_desc", g.getDesc());*/
				document.setField("item_sales",g.getSale());
				server.add(document);
			}
			server.commit();
		} catch (Exception e) {
			e.printStackTrace();
			return 0;
		}
		return 1;
	}

}
